/*
 * @FileName: boot.h
 * @Author: GreyQiu qiushaogui@aikosolar.com
 * @Date: 2023-08-23 17:36:10
 * @LastEditors: GreyQiu qiushaogui@aikosolar.com
 * @LastEditTime: 2023-09-20 10:08:54
 * @Description: 
 * 
 * Copyright (c) 2023, All Rights Reserved. 
 */

#ifndef __BOOT_H__
#define __BOOT_H__

#include <stdint.h>
#include <stdbool.h>
#include "bsp.h"

// BOOT状态

typedef enum {
    BOOT_STATUS_INIT = 0,
    BOOT_STATUS_ERASE,
    BOOT_STATUS_PROGRAM,
    BOOT_STATUS_CRC_OK
} boot_status_t;

typedef struct
{
    uint16_t status;
    uint16_t crc;
    uint32_t seq;
    uint32_t current_addr;
} boot_obj_t;

typedef struct
{
    uint32_t size;
    uint32_t ver;
    uint32_t crc;

    uint32_t size_bkp;
    uint32_t ver_bkp;
    uint32_t crc_bkp;
} app_head_t;

void boot_init(void);
ErrorStatus boot_enable(void);
ErrorStatus boot_disable(void);
ErrorStatus boot_app_erase(void);
ErrorStatus boot_app_program(uint8_t * buf, uint16_t len);
ErrorStatus boot_app_check_crc(uint16_t crc);
ErrorStatus boot_jumo_app(void);

#endif // __BOOT_H__
